package com.keggview.application.datatypes;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class PropertiesContainer implements Serializable {	
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6967506475795531733L;
	
	
	public PropertiesContainer() {
		this.attribs = new HashMap<String, String>();
	}
	
	public PropertiesContainer(HashMap<String, String> oldMap) {
		this.attribs = new HashMap<String, String> (oldMap);
	}
	
	/**
	 * Hashtable containing all key-value pairs saved for object
	 */
	private HashMap<String, String> attribs = null;
	
	/**
	 * add new attribute for object. If exist key with the same name. Old name will
	 * be replaced by new 
	 * @param key name of the parameter
	 * @param value value of the parameter
	 */
	public void addAttrib(String key, String value) {
		
		this.attribs.put(key, value);
	}
	
	/**
	 * add new unknown attribute for object. If exist key with the same name. 
	 * Old name will be replaced by new. From Object will be taken value from
	 * <tt>.toString()</tt> method. 
	 * @param key name of the parameter
	 * @param value value of the parameter
	 */
	public void addAttrib(String key, Object value) {
		
		this.attribs.put(key, value.toString());
	}
	
	/**
	 * gets attribute for object. If key will not exist, it will return <tt>null</tt>
	 * 
	 * @param key key looked for
	 * @return value of looked for key. If key will not exist it will return 
	 * <tt>null</tt>
	 * 
	 */
	public String getAttrib(String key) {
		String temp = this.attribs.get(key);
		return temp;
	}
	
	/**
	 * gets all keys of object
	 * @return Set of String with all attribute keys 
	 */
	public Set<String> getAllKeys() {
		return this.attribs.keySet();
	}
	
	/**
	 * removes all attributes
	 */
	public void clear() {
		Set<String> temp = this.getAllKeys();
		for(Iterator<String> i = temp.iterator();i.hasNext();) {
			String a = i.next();
			this.attribs.remove(a);
		}
	}
	
	/**
	 * removes key from list of attributes
	 * @param key key value which we want to delete
	 */
	public void remove(String key) {
		this.attribs.remove(key);
	}
}